# -*- coding: gb2312 -*-

from StockDailyFactorGeneralFunctions import StockDailyFactorGeneralFunctions
from PeriodFactorGeneralFunctions import PeriodFactorGeneralFunctions
import datetime
import time

class EPS_PE_PB_PEG:
    def __init__(self):
        self.baseStartDateStr = '2012-01-01'
        self.baseStartQuarterDateStr = '20120101'
        self.baseEndDateStr = '2017-05-01'

    def writeBaseEPS_ttmToMongoDB(self):
        baseStartDateStr = self.baseStartDateStr
        baseEndDateStr = self.baseEndDateStr

        windFactorNameStr = 'eps_ttm'
        colNameStr = 'eps_ttm'
        dbUpdateDateFiledStr = 'eps_ttm_update_date'
        dbUpdateDateFieldAliasStr = ' EPS_ttm '

        funcObj = StockDailyFactorGeneralFunctions()

        funcObj.writeBaseDataToMongoDB(baseStartDateStr, baseEndDateStr, windFactorNameStr, colNameStr, dbUpdateDateFiledStr, dbUpdateDateFieldAliasStr)

    def updateEPS_ttmToMongoDB(self):

        windFactorNameStr = 'eps_ttm'
        colNameStr = 'eps_ttm'
        dbUpdateDateFiledStr = 'eps_ttm_update_date'
        dbUpdateDateFieldAliasStr = ' EPS_ttm '

        funcObj = StockDailyFactorGeneralFunctions()

        funcObj.updateDataToMongoDB(windFactorNameStr, colNameStr, dbUpdateDateFiledStr, dbUpdateDateFieldAliasStr)


    def writeBasReciprocal_PE_ttmToMongoDB(self):
        baseStartDateStr = self.baseStartDateStr
        baseEndDateStr = self.baseEndDateStr

        windFactorNameStr = 'pe_ttm'
        colNameStr = 'reciprocal_pe_ttm'
        dbUpdateDateFiledStr = 'reciprocal_pe_ttm_update_date'
        dbUpdateDateFieldAliasStr = ' Reciprocal of PE_ttm '

        funcObj = StockDailyFactorGeneralFunctions()

        funcObj.writeBaseReciprocalDataToMongoDB(baseStartDateStr, baseEndDateStr, windFactorNameStr, colNameStr, dbUpdateDateFiledStr, dbUpdateDateFieldAliasStr)

    def updateReciprocal_PE_ttmToMongoDB(self):

        windFactorNameStr = 'pe_ttm'
        colNameStr = 'reciprocal_pe_ttm'
        dbUpdateDateFiledStr = 'reciprocal_pe_ttm_update_date'
        dbUpdateDateFieldAliasStr = ' Reciprocal of PE_ttm '

        funcObj = StockDailyFactorGeneralFunctions()

        funcObj.updateReciprocalDataToMongoDB(windFactorNameStr, colNameStr, dbUpdateDateFiledStr, dbUpdateDateFieldAliasStr)

    def writeBasePB_lfToMongoDB(self):
        baseStartDateStr = self.baseStartDateStr
        baseEndDateStr = self.baseEndDateStr

        windFactorNameStr = 'pb_lf'
        colNameStr = 'pb_lf'
        dbUpdateDateFiledStr = 'pb_lf_update_date'
        dbUpdateDateFieldAliasStr = ' PB_ttm '

        funcObj = StockDailyFactorGeneralFunctions()

        funcObj.writeBaseDataToMongoDB(baseStartDateStr, baseEndDateStr, windFactorNameStr, colNameStr, dbUpdateDateFiledStr, dbUpdateDateFieldAliasStr)

    def updatePB_lfToMongoDB(self):

        windFactorNameStr = 'pb_lf'
        colNameStr = 'pb_lf'
        dbUpdateDateFiledStr = 'pb_lf_update_date'
        dbUpdateDateFieldAliasStr = ' PB_lf '

        funcObj = StockDailyFactorGeneralFunctions()

        funcObj.updateDataToMongoDB(windFactorNameStr, colNameStr, dbUpdateDateFiledStr, dbUpdateDateFieldAliasStr)

    def writeBasePE_ttmToMongoDB(self):
        baseStartDateStr = self.baseStartDateStr
        baseEndDateStr = self.baseEndDateStr

        windFactorNameStr = 'pe_ttm'
        colNameStr = 'pe_ttm'
        dbUpdateDateFiledStr = 'pe_ttm_update_date'
        dbUpdateDateFieldAliasStr = ' pe_ttm '

        funcObj = StockDailyFactorGeneralFunctions()

        funcObj.writeBaseDataToMongoDB(baseStartDateStr, baseEndDateStr, windFactorNameStr, colNameStr, dbUpdateDateFiledStr, dbUpdateDateFieldAliasStr)

    def updatePE_ttmToMongoDB(self):

        windFactorNameStr = 'pe_ttm'
        colNameStr = 'pe_ttm'
        dbUpdateDateFiledStr = 'pe_ttm_update_date'
        dbUpdateDateFieldAliasStr = ' pe_ttm '

        funcObj = StockDailyFactorGeneralFunctions()

        funcObj.updateDataToMongoDB(windFactorNameStr, colNameStr, dbUpdateDateFiledStr, dbUpdateDateFieldAliasStr)

    def writeBaseRoaToMongoDB(self):
        baseStartDateStr = self.baseStartQuarterDateStr
        baseEndDateStr = self.baseEndDateStr

        windFactorNameStr = 'roa'
        colNameStr = 'roa'
        dbUpdateDateFiledStr = 'roa_update_date'
        dbUpdateDateFieldAliasStr = ' ROA report date '

        funcObj = StockDailyFactorGeneralFunctions()

        funcObj.writeBaseQuarterDataToMongoDB(baseStartDateStr, baseEndDateStr, windFactorNameStr, colNameStr, dbUpdateDateFiledStr, dbUpdateDateFieldAliasStr)

    def updateRoaToMongoDB(self):

        windFactorNameStr = 'roa'
        colNameStr = 'roa'
        dbUpdateDateFiledStr = 'roa_update_date'
        dbUpdateDateFieldAliasStr = ' ROA report date '

        objPeriodFactorGenFunc = PeriodFactorGeneralFunctions()
        allReportDateList = objPeriodFactorGenFunc.RetrievePeriodPointDateList('trans_dates', 'Q', self.baseStartQuarterDateStr, time.strftime('%Y%m%d'), 0)

        funcObj = StockDailyFactorGeneralFunctions()

        funcObj.updateQuarterDataToMongoDB(windFactorNameStr, colNameStr, dbUpdateDateFiledStr, dbUpdateDateFieldAliasStr, allReportDateList)

    def updateStmIssuingDatesToMongoDB(self):

        windFactorNameStr = 'stm_issuingdate'
        colNameStr = 'stm_issuingdate'
        dbUpdateDateFiledStr = 'stm_issuingdate_update_date'
        dbUpdateDateFieldAliasStr = ' STM Issuing date '

        objPeriodFactorGenFunc = PeriodFactorGeneralFunctions()
        allReportDateList = objPeriodFactorGenFunc.RetrievePeriodPointDateList('trans_dates', 'Q', self.baseStartQuarterDateStr, time.strftime('%Y%m%d'), 0)

        funcObj = StockDailyFactorGeneralFunctions()

        funcObj.updateQuarterIssuingDatesToMongoDB(windFactorNameStr, colNameStr, dbUpdateDateFiledStr, dbUpdateDateFieldAliasStr, allReportDateList)


#obj = EPS_PE_PB_PEG()
#obj.writeBaseEPS_ttmToMongoDB()
#obj.updateEPS_ttmToMongoDB()

#obj.writeBasReciprocal_PE_ttmToMongoDB()
#obj.updateReciprocal_PE_ttmToMongoDB()

#obj.writeBasePB_lfToMongoDB()
#obj.updatePB_lfToMongoDB()

#obj.writeBasePE_ttmToMongoDB()
#obj.updatePE_ttmToMongoDB()

#obj.updateRoaToMongoDB()

#obj.updateStmIssuingDatesToMongoDB()